package com.lekang.controller;

import com.lekang.R;
import com.lekang.ZcqEntity.BillVOZcq;
import com.lekang.ZcqEntity.elderlySysZcq;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lekang.le.service.wxBillZcqService;

import java.util.List;

@RestController
@RequestMapping("/api/bill")
@Log
public class wxBillZcqController {
    @Autowired
    private wxBillZcqService wxBillZcqService;
    @GetMapping("/elderly")
    public R getElderlyList(@RequestParam Long wxUserId) {
        if (wxUserId == null) {
            return R.error("微信用户ID不能为空");
        }
        List<elderlySysZcq> elderlyList = wxBillZcqService.getElderlyList(wxUserId);
        return R.ok(elderlyList);
    }
    @GetMapping("/list")
    public R getBillList(@RequestParam Long wxUserId, @RequestParam(required = false) Long elderlyId, @RequestParam(required = false) String transactionStatus) {
        if (wxUserId == null) {
            return R.error("微信用户ID不能为空");
        }
log.info( "wxUserId=" + wxUserId + ", elderlyId=" + elderlyId + ", transactionStatus=" + transactionStatus);
      List<BillVOZcq> list=  wxBillZcqService.getBillListZcq(wxUserId, elderlyId, transactionStatus);
        return R.ok(list);
    }
    @PutMapping("/pay")
    public R payBill(  Long billId) {
        int i=wxBillZcqService.payBill(billId);
        return  i>0?R.ok():R.error("支付失败");

    }
}
